package com.bdcom.autotest.ui.snp;

import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bdcom.autotest.MainFrame;
import com.bdcom.autotest.interaction.serial.manager.SerialPortManager;
import com.bdcom.autotest.interaction.serial.utils.ByteUtils;
import com.bdcom.autotest.interaction.serial.utils.ShowUtils;

import gnu.io.PortInUseException;
import gnu.io.SerialPort;

/**
 * 主界面
 * 
 */
public class PanelForVersion extends JFrame {
	private static Logger log = LoggerFactory.getLogger(PanelForVersion.class);
	// 程序界面宽度
	public final int WIDTH = 530;
	// 程序界面高度
	public final int HEIGHT = 430;

	// 数据显示区
	private JTextArea mDataView = new JTextArea();
	private JScrollPane mScrollDataView = new JScrollPane(mDataView);
	public PanelForVersion() {
//		this.mf = mf;
		initView();
		initComponents();
		initData();
	}

	/**
	 * 初始化窗口
	 */
	private void initView() {
		// 关闭程序
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		// 禁止窗口最大化
		setResizable(false);

		// 设置程序窗口居中显示
		Point p = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
		setBounds(p.x - WIDTH / 2, p.y - HEIGHT / 2, WIDTH, HEIGHT);
		this.setLayout(null);

		setTitle("版本信息");
	}

	/**
	 * 初始化控件
	 */
	private void initComponents() {

		// 数据显示
		mDataView.setFocusable(false);
		mScrollDataView.setBounds(10, 10, 500, 350);
		add(mScrollDataView);
	}

	/**
	 * 初始化数据
	 */
	private void initData() {
//		List<String> strList = readTxt("conf/version.txt");
		String val = "2022-1-17\n"+
					 "规定电源测试从1开始，如和设备上读取不一致则不通过\n"+
					 "2022-3-7\n"+
					 "hostswap测试添加按钮弹出的报文";
//					 "2022-3-4\n"+
//					 "添加测试日志导出";
//		for(String str:strList){
//			val+=str+"\n";
//		}
		mDataView.setText(val);
	}
	public List<String> readTxt(String txtPath) {
        File file = new File(txtPath);
        if(file.isFile() && file.exists()){
            try {
                FileInputStream fileInputStream = new FileInputStream(file);
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                List<String> strList = new ArrayList();
                String text = null;
                while((text = bufferedReader.readLine()) != null){
                	strList.add(text);
                }
                return strList;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}